package i7bac.container;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class ContainerGraph extends JPanel {

	// Current and maximum levels
	public int currentLevel, maxLevel;
	// Background and Foreground colors
	public Color background, foreground;
	/*
	 * A ContainerGraph draws a view of a Container
	 */
	public ContainerGraph(int currentLevel, int maxLevel, Color background, Color foreground) {
		super(true);
		this.currentLevel = currentLevel;
		this.maxLevel = maxLevel;
		this.background = background;
		this.foreground = foreground;
	}

	public void setMaxLevel(int newLevel) {
		this.maxLevel = newLevel;
		repaint();
	}

	public void setCurrentLevel(int newLevel) {
		this.currentLevel = newLevel;
		repaint();
	}

	private int getScaleY() {
		return getHeight() - getScaleHeight();
	}
	
	private int getScaleHeight() {
		return getHeight()*currentLevel/maxLevel;
	}
	
	public void paint(Graphics g) {
		g.setColor(background);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(foreground);
		g.fillRect(0, getScaleY(), this.getWidth(), getScaleHeight());
	}

}
